TOOL.Category			= "StargateFreak's LS Entities"
TOOL.Name				= "#Devices"

TOOL.DeviceName			= "Devices"
TOOL.DeviceNamePlural	= "Devices"
TOOL.ClassName			= "sf_ls3_entities"

TOOL.DevSelect			= true
TOOL.CCVar_type			= "generator_sf_bhc"
TOOL.CCVar_sub_type		= "generator_sf_bhc"
TOOL.CCVar_model		= "models/props_phx/misc/smallcannonball.mdl"

TOOL.Limited			= true
TOOL.LimitName			= "sf_ls3_entities"
TOOL.Limit				= 30

CAFToolSetup.SetLang("StargateFreak's LS Entities","Create Devices attached to any surface.","Left-Click: Spawn a Device.  Reload: Repair Device.")

function TOOL.EnableFunc()
	if not CAF then
		return false;
	end
	if not CAF.GetAddon("Resource Distribution") or not CAF.GetAddon("Resource Distribution").GetStatus() then
		return false;
	end
	return true;
end

TOOL.Renamed = {
	class = {
		water_generator = "generator_water_generator",
		sf_bhc = "generator_sf_bhc",
	},
	type = {
		water_generator = "generator_water_generator",
		sf_bhc = "generator_sf_bhc",
	},
}

local function gas_generator_func(ent,type,sub_type,devinfo,Extra_Data,ent_extras) 
	local volume_mul = 1 //Change to be 0 by default later on
	local base_volume = 4084
	local base_mass = 200
	local base_health = 600
	local res = ""
	if type == "generator_h2o_ramscoop" then
		res = "water"
	end
	ent.caf.custom.resource = res;
	CAF.GetAddon("Resource Distribution").RegisterNonStorageDevice(ent)
	local phys = ent:GetPhysicsObject()
	if phys:IsValid() and phys.GetVolume then
		local vol = phys:GetVolume()
		vol = math.Round(vol)
		MsgN("Ent Physics Object Volume: ",vol)
		volume_mul = vol/base_volume
	end
	ent:SetMultiplier(volume_mul)
	local mass = math.Round(base_mass * volume_mul)
	ent.mass = mass
	local maxhealth = math.Round(base_health * volume_mul)
	return mass, maxhealth 
end
local function blackhole_cache_func(ent,type,sub_type,devinfo,Extra_Data,ent_extras) 
	if type == "generator_sf_bhc" then
			local mini = 1024
			local volume_mul = 1
			local base_volume = 5000
			local base_mass = 50
			local base_health = 250
			local phys = ent:GetPhysicsObject()
			if phys:IsValid() and phys.GetVolume then
				local vol = phys:GetVolume()
				vol = math.Round(vol)
				volume_mul = vol/base_volume
			end
			CAF.GetAddon("Resource Distribution").AddResource(ent, "energy", math.Round(50000 * volume_mul * mini))
			CAF.GetAddon("Resource Distribution").AddResource(ent, "oxygen", math.Round(50000 * volume_mul * mini))
			CAF.GetAddon("Resource Distribution").AddResource(ent, "hydrogen", math.Round(50000 * volume_mul * mini))
			CAF.GetAddon("Resource Distribution").AddResource(ent, "carbon dioxide", math.Round(50000 * volume_mul * mini))
			CAF.GetAddon("Resource Distribution").AddResource(ent, "nitrogen", math.Round(50000 * volume_mul * mini))
			CAF.GetAddon("Resource Distribution").AddResource(ent, "liquid nitrogen", math.Round(50000 * volume_mul * mini))
			CAF.GetAddon("Resource Distribution").AddResource(ent, "water", math.Round(50000 * volume_mul * mini))
			CAF.GetAddon("Resource Distribution").AddResource(ent, "heavy water", math.Round(50000 * volume_mul * mini))
			CAF.GetAddon("Resource Distribution").AddResource(ent, "steam", math.Round(50000 * volume_mul * mini))
			CAF.GetAddon("Resource Distribution").AddResource(ent, "ZPE", math.Round(50000 * volume_mul * mini))
			CAF.GetAddon("Resource Distribution").AddResource(ent, "ZPH", math.Round(50000 * volume_mul * mini))
			CAF.GetAddon("Resource Distribution").AddResource(ent, "coolant", math.Round(50000 * volume_mul * mini))
			CAF.GetAddon("Resource Distribution").AddResource(ent, "naquadah", math.Round(50000 * volume_mul * mini))
			local mass = math.Round(base_mass * volume_mul)
			mass = 0.1
			ent.mass = mass
			local maxhealth = math.Round(base_health * volume_mul)
			return mass, maxhealth 	
	end
end
local function liquid_generator_func(ent,type,sub_type,devinfo,Extra_Data,ent_extras) 
	local volume_mul = 1 //Change to be 0 by default later on
	local base_volume = 4084 //Change to the actual base volume later on
	local base_mass = 60
	local base_health = 200
	if type == "generator_water_generator" then
		base_volume = 49738 //Change to the actual base volume later on
		base_mass = 120
		base_health = 350
	end
	CAF.GetAddon("Resource Distribution").RegisterNonStorageDevice(ent)
	local phys = ent:GetPhysicsObject()
	if phys:IsValid() and phys.GetVolume then
		local vol = phys:GetVolume()
		MsgN("Ent Physics Object Volume: ",vol)
		vol = math.Round(vol)
		volume_mul = vol/base_volume
	end
	ent:SetMultiplier(volume_mul)
	local mass = math.Round(base_mass * volume_mul)
	ent.mass = mass
	local maxhealth = math.Round(base_health * volume_mul)
	return mass, maxhealth 
end

TOOL.Devices = {
	generator_water_generator = {
		Name	= "Water Generator",
		type	= "generator_water_generator",
		class	= "generator_water_generator",
		func	= liquid_generator_func,
		devices = {
			large_phx = {
				Name	= "StargateFreak's Water Generator",
				model	= "models/LifeSupport/Generators/waterairextractor.mdl",
				skin	= 0,
				legacy	= false,
			},
		},
	},
	generator_sf_bhc = {
		Name	= "StargateFreak's Black-hole Cache",
		type	= "generator_sf_bhc",
		class	= "generator_sf_bhc",
		func	= blackhole_cache_func,
		AdminOnly = false,
		devices = {
			large_phx = {
				Name	= "StargateFreak's Black-hole Cache",
				model	= "models/props_phx/misc/smallcannonball.mdl",
				skin	= 0,
				legacy	= false,
			},
		},
	},
	generator_h2o_ramscoop = {
		Name	= "Water Ram Scoop",
		type	= "generator_h2o_ramscoop",
		class	= "generator_ramscoop",
		func	= gas_generator_func,
		devices = {
			normal = {
				Name	= "StargateFreak's Water RamScoop",
				model	= "models/LifeSupport/Generators/ramscoop.mdl",
				skin	= 0,
				legacy	= false, --these two vars must be defined per ent as the old tanks (defined in external file) require different values
			},
			Other = {
				Name	= "StargateFreak's Water RamScoop #2",
				model	= "models/props_lab/walllight001a.mdl",
				skin	= 0,
				legacy	= false, --these two vars must be defined per ent as the old tanks (defined in external file) require different values
			}
		},
	},
}


	
	
	
